<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/5/4
 * Time: 13:42
 */
class SpiderTest extends PHPUnit_Framework_TestCase
{

    public function testBase()
    {
        $object = new BookSpider\Spider();
        return $object;
    }

    /**
     * @depends testBase
     */
    public function testToUtf8($object)
    {
        $string = "Test 你好啊 utf8";
        $this->assertEquals('UTF-8', $object->checkEncoding($object->toUtf8($string)), 'method toUtf8 is error');
    }

    /**
     * @depends testBase
     */
    public function testCheckEncoding($object)
    {
        $string = "Test 你 utf8";
        $this->assertEquals('UTF-8', $object->checkEncoding($string), 'method checkEncoding is error');
    }

    /**
     * @depends testBase
     */
    public function testParseUrl($object)
    {
        $this->assertEquals('http://www.23wx.com/html/51/23/34.html', $object->parseUrl('http://www.23wx.com/html/{bookPrefix}/{bookId}/{chapterId}.html', array(51,23,34)), 'method parseUrl is error');
    }

    /**
     * @depends testBase
     */
    public function testGetMiddleText($object)
    {
        $this->assertEquals('|fsdofijkld1243iuoadfnk1l23uia|', $object->getMiddleText('a|mead|fsdofijkld1243iuoadfnk1l23uia|ccfx|dfosdf', 'mead', 'ccfx'), 'method GetMiddleText is error');
    }

    /**
     * @depends testBase
     */
    public function testMatch($object)
    {
        $this->assertNull($object->match(1,1), 'method match is error');
    }
}